import { defineStore } from "pinia";
import * as api from "../api/menu.js";
import routes from '../router/gerAll.js';
import recombination from "../utils/recoursion/index.js"
import statice from "../router/statice.js";


//动态路由
import dynamicRoutes from "../router/dynamic.js";
//引入总路由
import router from "../router/index.js";

// console.log(routes,"routessss");

export const usePermission = defineStore("usePermission", {
  state: () => {
    return {
      meunList: [],
    };
  },
  actions: {
    async getMeunList() {
      try {
        let res = await api.getMenuList();
        console.log(res, "res");
         let routesArr =  recombination(res.data.menuList,routes)
         this.meunList = routesArr
         //找到找到动态路由的path为“/”
         let target = dynamicRoutes.find(p=>{
           return p.path==="/"
         })
        //  console.log(target,"llll")
         target.children=[...this.meunList,...statice]

         router.addRoute(target,"kkkk")
        // console.log(recombination(res.data.menuList,routes),"recombination");
        
      } catch (error) {
        console.log(error);
      }
    },
  },
});
